home *** CD-ROM | disk | FTP | other *** search
- Path: castle.nando.net!news
- From: sekruege@nando.net (Steve Krueger)
- Newsgroups: comp.sys.amiga.programmer
- Subject: Re: SAS/C fopen("foo","a") -- is this a bug?
- Date: 9 Feb 1996 04:03:31 GMT
- Organization: News & Observer Public Access
- Message-ID: <4feh2j$7im@castle.nando.net>
- References: <zpfaa8aCCygGZ1@da23.darkness.gun.de>
- NNTP-Posting-Host: grail813.nando.net
- Mime-Version: 1.0
- Content-Type: text/plain; charset=iso-8859-1
- Content-Transfer-Encoding: 8bit
- X-NewsReader: Interworks_GRn 3.0 January 12, 1996
-
- In article <zpfaa8aCCygGZ1@da23.darkness.gun.de> zodiac@darkness.gun.de (Ralph Seichter) writes:
- : I used the following test program:
- :
- : ----------8<----------8<----------8<----------8<----------8<----------
- : /* test.c */
- :
- : #include <stdio.h>
- :
- : void main(void)
- : {
- : FILE *file;
- :
- : if (file = fopen("foo", "w"))
- : {
- : if (fprintf(file, "bar", 3) == 3)
- : printf("write ok\n");
- : fclose(file);
- : }
- :
- : if (file = fopen("foo", "a"))
- : {
- : if (fprintf(file, "bar", 3) == 3)
- : printf("append ok\n");
- : fclose(file);
- : }
- : }
- : ----------8<----------8<----------8<----------8<----------8<----------
- :
- : After I compiled this with SAS/C 6.56, I did the following in a shell:
- :
- : 1> sc link test.c
- : 1> date >foo
- : 1> protect foo r
- : 1> test
- : append ok
- :
- : The first fopen() with mode "w" fails, which is correct. But why can the
- : write-protected file "foo" be opened with mode "a", and why won't fprintf()
- : return an error? The file's contents are not changed, as is to be expected,
- : but fprintf() reports that three bytes were written, which is not true.
- :
-
-
- Here's what's happening. The fopen() "a" mode is translated to an
- Open() with MODE_OLDFILE, which succeeds, so the fopen() works.
-
- The fprintf eventually calls Write(), and that returns a success
- code too. Also, on my machine, the contents of foo are added to,
- so the routines in SC.LIB get no indication that the file
- is read only.
-
- I guess the only way to make this work as expected would be to
- have the level 1 SAS/C routines examine the protection bits
- before doing the Open(). They currently do not look at the
- protection bits in any way.
-
- sk
-